Part Number Hot Search : 
S40225S Q261A 2SA16 RAL1J A682F T6100215 CD40147 SGM3141B
Product Description
Full Text Search
 

To Download NUMAKER Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  n umaker brick dec 23 , 201 6 page 1 of 71 rev 1 . 00 nu maker brick design g uide arm ? cortex ? - m 4 32 - bit microcontroller numicro ? family nu maker brick design guide the information described in this document is the exclusive intellectual property of nuvoton technology corporation and shall not be reproduced without permission from nuvoton. nuvoton is providing this document only for reference purposes of numicro microcontroller based system design. nuvoton assumes no responsibility for errors or omis sions. all data and specifications are subject to change without notice. for additional information or questions, please contact: nuvoton technology corporation. www.nuvoton.com
n umaker brick dec 23 , 201 6 page 2 of 71 rev 1 . 00 nu maker brick design g uide table of contents 1 overview ................................ ................................ ......................... 7 2 NUMAKER brick platform introduction ................................ ............................ 8 NUMAKER brick platform concept ................................ ................................ ... 8 2.1 function - call setup() description ................................ ................................ .. 10 2.2 2.2.1 initialization of sensor module ................................ ................................ .............. 12 function - call loop() ................................ ................................ .................. 16 2.3 2.3.1 loop() overview ................................ ................................ .............................. 17 2.3.2 detailed description of loop() ................................ ................................ .............. 20 program file ................................ ................................ ........................... 24 2.4 3 communication layer of NUMAKER brick platform ................................ .......... 26 communication protocol of NUMAKER brick platform ................................ ........... 28 3.1 parameter format ................................ ................................ .................... 30 3.2 3.2.1 device descriptor ................................ ................................ ............................. 30 3.2.2 report descriptor ................................ ................................ ............................. 30 3.2.3 parameter information ................................ ................................ ....................... 33 4 adding a new sensor module ................................ ................................ . 34 hardware stage ................................ ................................ ....................... 35 4.1 4.1.1 setting id for new sensor module ................................ ................................ ......... 35 4.1.2 adding new hardware circuit on expansion module board ................................ ........... 36 software stage ................................ ................................ ........................ 37 4.2 4.2.1 program initialization section ................................ ................................ ............... 38 4.2.2 program execution section ................................ ................................ ................. 40 5 NUMAKER brick connected with arduino ................................ ...................... 42 necessary function - calls for all sensor modules ................................ ............... 42 5.1 5.1.1 function - call setup() ................................ ................................ ......................... 42 5.1.2 function - call loop() ................................ ................................ .......................... 42 adding a new arduino module ................................ ................................ ..... 44 5.2 5.2.1 hardware stage ................................ ................................ ............................... 44 5.2.2 software stage ................................ ................................ ................................ 44 6 appendix a - app design concept ................................ ........................... 47 index page ................................ ................................ ............................. 48 6.1 device link page ................................ ................................ ..................... 51 6.2 sensor module page ................................ ................................ ................. 54 6.3
n umaker brick dec 23 , 201 6 page 3 of 71 rev 1 . 00 nu maker brick design g uide 7 appendix b - sensor module parameter information ................................ ....... 60 battery module ................................ ................................ ........................ 61 7.1 buzzer module ................................ ................................ ........................ 62 7.2 led module ................................ ................................ ............................ 64 7.3 vibration module ................................ ................................ ...................... 66 7.4 sonar module ................................ ................................ .......................... 67 7.5 temperature module ................................ ................................ ................. 68 7.6 8 revision history ................................ ................................ ............ 70
n umaker brick dec 23 , 201 6 page 4 of 71 rev 1 . 00 nu maker brick design g uide list of figures figure 2 - 1 combination example of NUMAKER brick platform ................................ ......................... 8 figure 2 - 2 function - calls of sensor modules in modular programming table ............................... 9 figure 2 - 3 setup() initialization flowchart ................................ ................................ ..................... 10 figure 2 - 4 setup() function - call program ................................ ................................ ..................... 12 figure 2 - 5 initialization program of battery sensor module ................................ .......................... 15 figure 2 - 6 loop() on master and sensor module flowchart ................................ ......................... 16 figure 2 - 7 loop() program description ................................ ................................ ......................... 19 figure 2 - 8 periodic program of sensor module ................................ ................................ ............. 20 figure 2 - 9 structural function table of sensor modules ................................ .............................. 20 figure 2 - 10 non - periodic program of sensor module ................................ ................................ ... 21 figure 2 - 11 non - periodic program of sensor module ................................ ................................ ... 21 figure 2 - 12 structural function table of sensor modules ................................ ............................ 21 figure 2 - 13 the feedback setting from master module to sensor modules ................................ . 22 figure 2 - 14 sensor module trigger settings ................................ ................................ .................. 23 figure 3 - 1 communication architechture between master and sensor module ........................... 26 figure 3 - 2 communication protocol between master and sensor module ................................ ... 28 figure 4 - 1 expansion module board ................................ ................................ .............................. 34 figure 4 - 2 partial schematics of mcu and id check of expansion module board ...................... 35 figure 4 - 3 complete schematic diagram of new photoresistor s ensor module .......................... 36 figure 4 - 4 function - calls of new sensor module in modular programming table ...................... 38 figure 4 - 5 photoresistor sensing module initialization program ................................ ................... 40 figure 4 - 6 structural function table of sensor modules ................................ .............................. 41 figure 5 - 1 initialization program of setup() for all sensor modules ................................ .............. 42 figure 5 - 2 program execution of loop() for all sensor modules ................................ ................... 43 figure 5 - 3 schematic diagram of arduino mega and arduino rgb led module ....................... 44 figure 5 - 4 led initialization program in setup() for arduino led module ................................ .... 45 figure 5 - 5 led execution program in loop() for arduino led module ................................ ......... 46 figure 6 - 1 index page ................................ ................................ ................................ .................... 48 figure 6 - 2 device link page ................................ ................................ ................................ .......... 51 figure 6 - 3 buzzer module page ................................ ................................ ................................ .... 55
n umaker brick dec 23 , 201 6 page 5 of 71 rev 1 . 00 nu maker brick design g uide list of tables table 2 - 1 programs of master module ................................ ................................ .......................... 24 table 2 - 2 programs of sensor module ................................ ................................ .......................... 25 table 3 - 1 parameter specification of sensor module ................................ ................................ ... 27 table 3 - 2 device descriptor format ................................ ................................ .............................. 30 table 3 - 3 report descriptor format ................................ ................................ .............................. 32 table 3 - 4 parameter format ................................ ................................ ................................ .......... 33 ta ble 4 - 1 id identifying by different resistance and adc voltage for new sensor module ........ 36 table 4 - 2 software modification on master module and new sensor module .............................. 37 table 6 - 1 data format that app received in the first stage of index page ................................ 49 table 6 - 2 data format that app received in the second stage of index page ........................... 50 table 6 - 3 data format that app received in the first stage of device link page ...................... 52 table 6 - 4 data format that app received in the second stage of device link page ................. 52 table 6 - 5 commands supported in the set stage ................................ ................................ ........ 53 table 6 - 6 commands to switch to sensor module page ................................ .............................. 54 table 6 - 7 received data on sensor module page in the first stage ................................ ........... 56 table 6 - 8 received data on sensor module page in the second stage ................................ ...... 58 table 6 - 9 received data on sensor module page in the third stage ................................ .......... 58 table 6 - 10 updating commands of sensor module ................................ ................................ ...... 59 table 6 - 11 commands for modifying each sensor module parameter ................................ ........ 59 table 7 - 1 device descriptor of battery module ................................ ................................ ............. 61 table 7 - 2 feature parameter of battery module ................................ ................................ .......... 61 table 7 - 3 input parameter of battery module ................................ ................................ ................ 61 table 7 - 4 device descriptor of buzzer module ................................ ................................ ............. 62 table 7 - 5 feature parameter of buzzer module ................................ ................................ ........... 62 table 7 - 6 input parameter of buzzer module ................................ ................................ ................ 62 table 7 - 7 output parameter of buzzer module ................................ ................................ ............ 63 table 7 - 8 device descriptor of led module ................................ ................................ .................. 64 table 7 - 9 feature parameter of led module ................................ ................................ ............... 64 table 7 - 10 input parameter of led module ................................ ................................ .................. 65 table 7 - 11 output parameter of led module ................................ ................................ .............. 65 table 7 - 12 device descriptor of vibration module ................................ ................................ ........ 66 table 7 - 13 feature parameter of vibration module ................................ ................................ ....... 66 table 7 - 14 input parameter of vibration module ................................ ................................ .......... 66 table 7 - 15 device descriptor of sonar module ................................ ................................ ............. 67 table 7 - 16 feature parameter of sonar module ................................ ................................ ........... 67 table 7 - 17 input parameter of sonar module ................................ ................................ ................ 67
n umaker brick dec 23 , 201 6 page 6 of 71 rev 1 . 00 nu maker brick design g uide table 7 - 18 device descriptor of temperature module ................................ ................................ .. 68 table 7 - 19 feature parameter of temperature module ................................ ................................ 68 table 7 - 20 input parameter of temperature module ................................ ................................ ..... 68 table 7 - 21 device descriptor of gas module ................................ ................................ ................ 69 table 7 - 22 feature parameter of gas module ................................ ................................ .............. 69 table 7 - 23 input parameter of gas module ................................ ................................ ................... 69
n umaker brick dec 23 , 201 6 page 7 of 71 rev 1 . 00 nu maker brick design g uide 1 overview NUMAKER brick is a highly integrated platform designed to support iot (internet of things) for users to develop their design s quickly. every sensor has its own function. the combination module allows the NUMAKER brick platform to create application - specific produ cts with high flexibility. besides, the NUMAKER brick provides an expansion board such that u sers can create their own specific sensor and extend the function on the NUMAKER brick platform. since the biggest challenge for developers is not to add new funct ion s , but to integrate the other module , t he NUMAKER brick platform is equipped with a unified communication protocol such that users can a dd a new module designed only in accordance with the specifications for the communication protocol. this can significantly reduce the complexity of developing the new modules a nd help developer s to focus more on developing new module s to meet the product schedule. this document guides users to add a new module on the NUMAKER brick platform step by step from basic platform architecture introduction to software design concept and communicated protocol. this document also assists developers to build a complete platform operation concept based on detailed explanation of a practical example.
n umaker brick dec 23 , 201 6 page 8 of 71 rev 1 . 00 nu maker brick design g uide 2 n umaker brick platform intr oduction NUMAKER brick platform concept 2.1 the NUMAKER brick platform consists of a master module and some slave sensor modules. the master module collects and processes all the parameter received from each of the sensor modules. before receiving or transmitting parameter from/to the master module, each of sensor modules always needs to wait for the call and execute the received commands from master module. figure 2 - 1 shows the combination example of NUMAKER brick platform between a master module and two slave sensor modules. figure 2 - 1 com b ination example of NUMAKER brick platform t his chapter introduce s the NUMAKER brick platform program and it s main function. the main function is to put in main.c and can be divided into two part s : setup() and loop(). se tup() is used to do the initial operation ; l oop() is where the NUMAKER brick platform execute s program. t he next chapter will introduce the two parts and the entire framework of the platform . t o modular ize program, the module s are classified by the following function s : ? module initialization: initialization function for each module ? function executing program periodically: module is required to execute periodically. ? function executing program immediately: module is required to execute immediately. figure 2 - 2 shows all the function - calls of sensor module s in modular program ming table and the classification of sensor functions . u sers can eas ily add new function s of new module s into this structural function table according to their demands in application system . v i b r a t i o n b u z z e r c a l l s e n s o r m o d u l e i a m v i b r a t i o n m o d u l e , i h a v e d a t a . . . i a m b u z z e r m o d u l e , i h a v e d a t a . . . m a s t e r
n umaker brick dec 23 , 201 6 page 9 of 71 rev 1 . 00 nu maker brick design g uide apfn_func_t pfndevfunc[max_tid_dev] = { /* functions for each device: {initial, period, pulling, report} initial : init and configure device period : process device sensor parameter or set sensor once per 0.1 seconds. p o lling : process device sensor parameter or set sensor frequently. report : report process parameter to master */ /* for embedded device boards */ {battery_init, mastercontrol, null, report_battery}, {buzzer_init, null, buzzer_control, report_buzzer}, {led_init, null, led_control, report_led}, {ahrs_init, ahrs_control, ahrs_cal, report_ahrs}, {sonarinit, sonardetect, sonartimeoutcheck, report_sonar}, {htu21d_init, waithtu21d, gethtu21dtemp, report_temp}, {gas_init, getgas, null, report_gas}, {ir_init, ir_control, ir_check, report_ir}, {key_init, null, null, report_key}, /* for custom device boards fill your four board functions here to specified id. */ {lr_init, getlr, null, report_resdev9}, // for device id 9 {null, null, null, report_resdev10}, // for device id 10 {null, null, null, report_resdev11}, // for device id 11 {null, null, null, report_resdev12}, // for device id 12 {null, null, null, report_resdev13}, // for device id 13 {null, null, null, report_resdev14} // for device id 14 }; figure 2 - 2 function - calls of sensor modules in modular program ming table sensor f unction s execute d period ical ly sensor f unction s execute d immediately u ser s can define sensor function s by themsel ves sensor m odule initi aliz ation
n umaker brick dec 23 , 201 6 page 10 of 71 rev 1 . 00 nu maker brick design g uide function - call setup () description 2.2 figure 2 - 3 shows the setup() function - c all initialization flowchart . figure 2 - 3 s etup() initialization flowchart s t a r t s e t s y s t e m f r e q u e n c y s e t u a r t c h e c k i d s e t i 2 c c h e c k f l a s h m o d u l e i n i t i a l i z i n g s a v e p l a t f o r m d a t a i n t o i 2 c v a r i a b l e s e t t i m e r e n d
n umaker brick dec 23 , 201 6 page 11 of 71 rev 1 . 00 nu maker brick design g uide the setup() function - call flow is described as follows . figure 2 - 4 shows the whole program code of setup() function - call . 1. set the system clock as 72mhz for cpu. 2. set the baud rate as 115200bps for uart. 3. ch eck id to identify this module is master o r slave device on i 2 c bus of this NUMAKER brick platform. 4. in itialize the i 2 c peripheral of this module by id. 5. initialize the flash memory. 6. i nitializ e the module , including four steps: ? check id ? initialize module function ? check whether there is a corresponding parameter in flash. read flash data according to the value of id ? set the period of function executing 7. set the module parameter for i2c ? the master module saves the next parameter that will be transmitted to the sensor module. void setup() { int i; setupsystemclock(); setupuart(); setup_system_tick(system_tick_freq); id_init(); getid(); /* init ahrs i2c */ /* ---- initialize i2c slave mode --- */ if(devnum == 0) i2c_ms_master_init(); else i2c_ms_slave_init(); t idmstfirstinitfin = 0; tidmstinitfin = 0; tidmststage = 0; tidmstinitdevstate = 1; flashinit( ); 2. set uart baud rate 1. set system clock 3. c heck id 4 . i 2 c initialization according to id 5. i nitia liza tion for flash
n umaker brick dec 23 , 201 6 page 12 of 71 rev 1 . 00 nu maker brick design g uide // set function pointers for default sensor boards. for(i=0; ifunc.pfnsetup) ptidlist[devnum] - >func.pfnsetup(); // load tid feature from flash getflashtid(&(ptidlist[devnum] - >feature), devnum); // set timer1 to (1000/value) in (hz) timer1init(1000 / (ptidlist[devnum] - >feature.data1.value)); /* tid initialize */ slvdatainit(); mstdatainit(); } figure 2 - 4 s etup() f unction - c all program 2.2.1 initialization of sensor module the following section introduces the sensor module initialization program content. battery_init() code is used as an example . at the initializing program, the first part is the module initialize; the second part is the data setting s transfer between m aster and slave. following is the data setting format. 1. first, set the data needed. the photoresistor module s data is as follows . ? sleep period: t he periodic time to monitor the sensor module ? trigger alarm value: t o trigger the alarm when the sensor value is above/below th e value ? sensor value: t he current value of sensor module ? alarm: t o turn on/off alarm 2. s tatus classification : feature, output and input ? feature: some settings of sensor module that don t need to tr ansmit or receive da ta frequently . ? output: m aster transmits the information to the slave sensor module. ? input: master receives the information from the slave sensor module . 6 . i niti aliz ation for each sensor module 7 . save module parameter s into i 2 c variable s
n umaker brick dec 23 , 201 6 page 13 of 71 rev 1 . 00 nu maker brick design g uide f or example, a battery sens or module has two f eature parameters : sleep p eriod to monitor the battery voltage periodically and trigger a larm v alu e to trigger alarm when the battery voltage is below this setting value. moreover, the battery sens or module has two i nput parameters : sensor value to show the current b attery voltage v alue and alarm to show the alarm on/off status on the battery sensor module . 3. set the parameters of each sensor module: ? maximum, minimum: show in brown block (as the following figure ) , which is set by data range that is required. ? position (arg): i ndicate the data position of the classification and the location should be incre ased sequentially. ? length (datalen): represent the length of data and its unit is byte . ? value: represents the current setting value of data. ? data number (datanum): represent the number of data that will be transmitted or received to/from the master module. for example , there are two input data for the sensor module and the datanum should be set as 2.
n umaker brick dec 23 , 201 6 page 14 of 71 rev 1 . 00 nu maker brick design g uide void battery_init() { sys_unlockreg(); /* enable eadc module clock */ clk_enablemoduleclock(eadc_module); /* eadc clock source is 72mhz, set divider to 8, adc clock is 72/8 mhz */ clk_setmoduleclock(eadc_module, 0, clk_clkdiv0_eadc(8)); sys_lockreg(); /* configure the gpb0 - gpb3 adc analog i nput pins. */ sys - >gpb_mfpl &= ~sys_gpb_mfpl_pb1mfp_msk; sys - >gpb_mfpl |= sys_gpb_mfpl_pb1mfp_eadc_ch1; gpio_disable_digital_path(pb, bit1); //led sys - >gpa_mfpl &= ~(sys_gpa_mfpl_pa2mfp_msk); sys - >gpa_mfpl |= sys_gpa_mfpl_pa2mfp_gpio; gpio_setmode( pa,bit2,gpio_mode_output); pa2 = 1; /* set the adc internal sampling time, input mode as single - end and enable the a/d converter */ eadc_open(eadc, eadc_ctl_diffen_single_end); eadc_setinternalsampletime(eadc, 6); /* configure the sample module 0 for analog input channel 1 and software trigger source.*/ eadc_configsamplemodule(eadc, 1, eadc_software_trigger, 1); /* clear the a/d adint0 interrupt flag for safe */ eadc_clr_int_flag(eadc, 0x2); /* enable the sample module 0 interrupt */ eadc_enable_int(eadc, 0x2); //enable sample module a/d adint0 interrupt eadc_enable_sample_module_int(eadc, 1, 0x2); //enable sample module 0 interrupt batdev.devdesc.devdesc_leng = 26; //report descriptor batdev.devdesc.rptdesc_leng = 36; //report descriptor batdev.devdesc.inrptleng = 5; //input report batdev.devdesc.outrptleng = 0; //output report batdev.devdesc.getfeatleng = 6; //get feature ba tdev.devdesc.setfeatleng = 6; //set feature i niti aliz ation of sensor module s ettings of sensor module will be passed to master module
n umaker brick dec 23 , 201 6 page 15 of 71 rev 1 . 00 nu maker brick design g uide batdev.devdesc.cid = 0; //manufacturers id batdev.devdesc.did = 0; //product id batdev.devdesc.pid = 0; //device firmware revision batdev.devdesc.uid = 0; //device class type batdev.devdesc.ucid = 0; //reserve /* feature */ batdev.feature.data1.minimum = 0; //sleep period batdev.feature.data1.maximum = 1024; batdev.feature.data1.value = 100; batdev.feature.data2.minimum = 0; //battery alerm value batdev.feature.data2.maximum = 100; batdev.feature.data2.value = 50; batdev.feature.arg[0] = 1; batdev.feature.arg[1] = 2; batdev.feature.datalen[0] = 2; batdev.feature.datalen[1] = 2; batdev.feature.datanum = 2; /* input */ batdev.input.data1.minimum = 0; //battery value batdev.input.data1.maximum = 100; batdev.input.data1.value = 100; batdev.input.data2.minimum = 0; //over flag batdev.input.data2.maximum = 1; batdev.input.data2.value = 0; batdev.input.arg[0] = 1; batdev.input.arg[1] = 2; batdev.input.datalen[0] = 2; batdev.input.datalen[1] = 1; batdev.input.datanum = 2; /* output */ batdev.output.datanum = 0; } figure 2 - 5 initialization program of battery sensor module device descriptor feature input output s leep p eriod trigger alarm vaule p arameter position parameter length parameter number sensor vaule alarm flag parameter number parameter number parameter length parameter position
n umaker brick dec 23 , 201 6 page 16 of 71 rev 1 . 00 nu maker brick design g uide f unction - call loop () 2.3 figure 2 - 6 represents the flowchart of loop() function - call for the master module and slave sensor module. the loop() function - call is the main program code that executed in master or sensor module. the left flowchart is for master module and the right flowchart is for the slave sensor module. the loop() function - call can be separated into two sections: period section and non - period i c section. ? period section works once at every setting time. for example, the vibration sensor module will update data every 0.1 second. ? non - period ic section always is executed. typically, it is used to check or react immediately on the sensor module. for e xample, the sonar sensor module collects continuously the distance information from the surrounding. figure 2 - 6 l oop() on master and sensor module flowchart s t a r t u p d a t e d a t a r e c e i v e d f r o m s l a v e u p d a t e c o m m u n i c a t i o n s t a t e c o m m u n i c a t e w i t h a p p a s k s l a v e d a t a e v e r y 0 . 1 s i d e n t i f y w h e t h e r s l a v e e x i s t e v e r y 1 s e n t e r l o o p y e s n o s t a r t e x e c u t e s e n s o r p e r i o d p r o g r a m u p d a t e d a t a f r o m m a s t e r e x e c u t e s e n s o r n o n - p e r i o d p r o g r a m s t o r e d a t a w i l l t r a n s f e r t o m a s t e r i n t o i 2 c e n t e r l o o p y e s n o
n umaker brick dec 23 , 201 6 page 17 of 71 rev 1 . 00 nu maker brick design g uide 2.3.1 loop () overview the follow ing d escribe s the loop() function - call . figure 2 - 7 shows the whole program code of loop() function - call . period execution section (inside of if(tmr1intcount != recenttimecounter) area): 1. master module i. communication with app. ii. update p arameter which will be transmitted to slave module. iii. update communication state with each sensor module (using i 2 c). master will communicate with each slave module periodically to get the newest parameter . 2. sensor module: i. execute the period program of sensor module. non - period ic execution section (outside of if(tmr1intcount != recenttimecounter) area): 3. master module i. ask each sensor module by i 2 c every 0.1s , i ncluding set feature, get feature, set output and get input . ii. check whether the sens or module is connected or disconnected every 1 second, including device descriptor and report descriptor receiving. 4. sensor module: i. u pdate output signal from mas ter. ii. executes non - period ic program . iii. store p arameter which will be transmitted to master by i 2 c.
n umaker brick dec 23 , 201 6 page 18 of 71 rev 1 . 00 nu maker brick design g uide void loop() { commandprocess(); taskscheduler(); powercontrol(); // ****************************************************** // get parameter for once e v ery 0.1s // ****************************************************** if(tmr1intcount != recenttimecounter) { maintimemscounter = gettickcount(); if (ptidlist[devnum] - >func.pfnperiod) ptidlist[devnum] - >func.pfnperiod(); recenttimecounter = tmr1intcount; } // =============tid master handle received parameter =============== // ----------- tid master handle received parameter ------------ if(devnum == 0) { if(tidmstinitfin==0) { tidmst_getdev(); } else if(tidmstinitfin==1) { tidmstdevtrx(); } } // ==================== slave part ====================== // ----------- tid slave handle received parameter -------------- else { if(i2cms_slvrxfin==1) tid_slvrxupdate(); } 1 - : c ommunicat ion with app 1 - : update parameter which will be transmitted to slave 1 - : update communication state with each sensor module 2 - : p eriod ic program of sensor module 4 - : sensor u pdate s the received parameter from master 3 - : master ask s each sensor for parameter by i 2 c every 0.1s 3 - : master identif ies whether sensor module is presen t or absen t every 1 second
n umaker brick dec 23 , 201 6 page 19 of 71 rev 1 . 00 nu maker brick design g uide // ----------- slave part ex e cute subfunction -------------- if (ptidlist[devnum] - >func.pfnpulling) ptidlist[devnum] - >func.pfnpulling(); // -------------- tid slave store parameter ----------------- if(devnum != 0) slvdatastore(); } figure 2 - 7 loop () program description 4 - : sensor module executes n on - period ic function 4 - : sensor module s tor es parameter which will be transmitted to master into variable s for i 2 c
n umaker brick dec 23 , 201 6 page 20 of 71 rev 1 . 00 nu maker brick design g uide 2.3.2 detailed description of l oop () the NUMAKER brick platform support s two stage s t o meet the needs of different conditions . the first stage is the function program executed periodically for sensor module s as shown in figure 2 - 8 . // ****************************************************** // get parameter for once e v ery 0.1s // ****************************************************** if(tmr1intcount != recenttimecounter) { maintimemscounter = gettickcount(); if (ptidlist[devnum] - >func.pfnperiod) ptidlist[devnum] - >func.pfnperiod(); recenttimecounter = tmr1intcount; } figure 2 - 8 periodic program of sensor m odule t he sensing program e xecut ed periodic ally show n in figure 2 - 8 must correspond with the periodic function of a master or sensor modul e , as shown in figure 2 - 9 . apfn_func_t pfndevfunc[max_tid_dev] = { ... /* for embedded device boards */ {battery_init, mastercontrol, null, report_battery}, {buzzer_init, null, buzzer_control, report_buzzer}, {led_init, null, led_control, report_led}, {ahrs_init, ahrs_control, ahrs_cal, report_ahrs}, {sonarinit, sonardetect, sonartimeoutcheck, report_sonar}, {htu21d_init, waithtu21d, gethtu21dtemp, report_temp}, {gas_init, getgas, null, report_gas}, {ir_init, ir_control, ir_check, report_ir}, {key_init, null, null, report_key}, ... }; figure 2 - 9 structural function table of sensor modules 2 - : p eriod ic program of sensor module sensor f unction s execute d period ical ly
n umaker brick dec 23 , 201 6 page 21 of 71 rev 1 . 00 nu maker brick design g uide the following description us e s the vibration sensor module as an example. void ahrs_control(void) { sensorsread(sensor_acc|sensor_gyro,1); nvtupdateahrs(sensor_acc|sensor_gyro); ahrsread(ahrsdev.feature.data2.value, ahrsdev.feature.data3.value, ahrsdev.output.data1.value); //(vibration level, alerm time, clear flag) } figure 2 - 10 n on - p eriod ic program of sensor m odule in t he second stage , the function program will be check ed or execute d continuously and this program section is outside of the if(tmr1intcount != recenttimecounter){} block. // ----------- slave part ex e cute subfunction -------------- if (ptidlist[devnum] - >func.pfnpulling) ptidlist[devnum] - >func.pfnpulling(); figure 2 - 11 n on - p eriod ic program of sensor m odule the sensing program executed non - periodically shown in figure 2 - 11 must correspond with the no n - periodic function of a master or sensor module as shown in figure 2 - 12 . apfn_func_t pfndevfunc[max_tid_dev] = { ... /* for embedded device boards */ {battery_init, mastercontrol, null, report_battery}, {buzzer_init, null, buzzer_control, report_buzzer}, {led_init, null, led_control, report_led}, {ahrs_init, ahrs_control, ahrs_cal, report_ahrs}, {sonarinit, s onardetect, sonartimeoutcheck, report_sonar}, {htu21d_init, waithtu21d, gethtu21dtemp, report_temp}, {gas_init, getgas, null, report_gas}, {ir_init, ir_control, ir_check, report_ir}, {key_init, null, null, report_key}, ... }; figure 2 - 12 structural function table of sensor modules 4 - : sensor module executes n on - period ic function sensor f unction s execute d immediately
n umaker brick dec 23 , 201 6 page 22 of 71 rev 1 . 00 nu maker brick design g uide a fter setting the sensor module is finished , s et the master , i ncluding setting trigger source from a new module. the master control program can be found in pfndevfunc which is located at main.c. tidmstupdatedevstate is in master control. refer to figure 2 - 13 . void mastercontrol(void) { /* master store parameter */ tidmstupdatedevstate(); /* master recheck device */ if(tidmstfirstinitfin==1) { if(tmr1timercounter > 10) { if( i2cmstendflag==1) { tidmstinitfin=0; tmr1timercounter=0; i2c_close(i2c_ms_port); i2c_ms_master_restart(); } } else { tidmstinitfin = 1; tmr1timercounter++; } } getbattery(); } figure 2 - 13 the f eedback s etting from m aster module to sens or module s the example of tidmstupdatedevstate() is shown below: // ******************************************************* // master handle device state // ******************************************************* void tidmstupdatedevstate() { ... if((ahrsdev.input.data2.value==1) && (tidmstinitdevstate & (1< n umaker brick dec 23 , 201 6 page 23 of 71 rev 1 . 00 nu maker brick design g uide { if(buzdev.dtod.dthr==1) { buzdev.output.data1.value = 1; //song tidmstdevstate[buzzerdev] |= 2; //buzzer operate: output(2) } ... } figure 2 - 14 sensor module trigger s ettings tak ing the vibration module as an example, this program uses the following function : i f t he received parameter from vibration module is 1 : if (ahrsdev.input.data2.value==1) i f t here is relationship between the buzzer and vibration module : if (buzdev.dtod.dthr==1) master ask s buzzer to beep : buzdev.output.data1.value = 1 t here is relationship between buzzer and vibration module m aster ask buzzer to beep
n umaker brick dec 23 , 201 6 page 24 of 71 rev 1 . 00 nu maker brick design g uide program f ile 2.4 the NUMAKER brick function can be divided into two part s: ? master function: includes the NUMAKER brick platform architecture and communication protocol with app. refer to table 2 - 1 . ? slave function: the sensor module program. refer to table 2 - 2 . master module program name program description i 2 c i2c_ms i 2 c communication setting on the platform i2cdev i 2 c communication function - call platform parameter tid platform parameter setting tidmst master platform parameter storage methods tiddev slave platform parameter storage methods id check devcheck id check in each module app communication report app communication setting report_ap app communication function - call table 2 - 1 programs of master module sensor module program name program description battery battery us e adc detect battery led led us e pwm driving led buzzer buzzer us e pwm driving buzzer music music mapping table gas gas us e adc detect gas ir ir us e pwm driving ir and using capture to detect ir pwm0p2 irs pwm setting and interrupt executing sonar sonar us e pwm capture get sonar signal temperature temp_htu21d us e i 2 c to receive temperature and humidity signal i2c_htu21d i 2 c communication setting on the temperature module vibration ahrs us e i 2 c to receive vibration signal calibrate calibrate vibration module mpu6050 i 2 c communication setting on the vibration module sensors arrange vibration module parameter
n umaker brick dec 23 , 201 6 page 25 of 71 rev 1 . 00 nu maker brick design g uide button key button module function gpc_irq us e pc interrupt to receive button state gpe_irq us e pe interrupt to receive button state period s etting timerirq1 set the execution period at each module table 2 - 2 programs of sensor module
n umaker brick dec 23 , 201 6 page 26 of 71 rev 1 . 00 nu maker brick design g uide 3 c ommunication l ayer of n umaker b rick p latform this chapter introduce s the whole data transmission throughout the expansion platform. the first section will explain how to reach to the two targets that mentioned previously on this platform. figure 3 - 1 communication architechture between master and sensor module the NUMAKER brick platform can be divided into three parts: ? master module : a rrange the data which is received from other module or send parameter to other module. ? sensor m odule: to monitor or detect any changes in the surrounding and transmit these parameter to master module . ? communication l ayer : communication layer dispersed in master and sensor module. it is established to accomplish two objectives mentioned previously d evice s calability and parameter consistency. therefore, the parameter must be standardized that common market sensor module have. let master can gather information and send command to sensor module. in t he platform , the master collects information from sensor module, and sends command to other device. it is important to let master know sensor module parameter . ? parameter classification: set consistent format for each sensor parameter (including maximum value , minimum value and the current value). ? module expansibility: separate e ach sensor information into three class es ( f eature , i nput and o utput ). i t also record s the length and position of each parameter on each class. the second section will describe the protocol be tween master module and sensor modules . the last section will explain th e ir parameter formats of sensor modules . the communication between master and sensor module can be processed by i 2 c which is defined as communication layer. each parameter defined in the communication layer for all sensor modules is shown in table 3 - 1 . p arameter class p arameter content sensor module feature maximum minimum m a s t e r s e n s o r c o m m u n i c a t i o n l a y e r c o m m u n i c a t i o n l a y e r p a r a m e t e r
n umaker brick dec 23 , 201 6 page 27 of 71 rev 1 . 00 nu maker brick design g uide length order value output maximum minimum length order value input maximum minimum length order value table 3 - 1 parameter specification of sensor module e ach parameter has the following information: ? p arameter range: t he maximum and minimum value s of p arameter . ? p arameter length: t he length of p arameter . ? p arameter order: t he position of p arameter in the classification. ? p arameter content: t he current parameter value . the communication level also classifies all p arameter for all sensor module s to a void the unnecessary transmission of p arameter during the communication. there are three types of classes as described below . ? feature: the specific information of sensor module, e.g. the frequency of buzzer, the distance for sonar to alarm. ? input: the information trans mitted from sensor module to master module , e.g. the real d istance of sonar , the vibration event . ? output: the c ommand transmitted from m aster module to sensor module, e.g. led blink command. these classes are all the same on both master module and sensor module. the i nput and o utput definition are from the view of master module .
n umaker brick dec 23 , 201 6 page 28 of 71 rev 1 . 00 nu maker brick design g uide communication p rotocol of NUMAKER brick platform 3.1 the communication pro tocol and flow can be classified into three stages as shown in figure 3 - 2 . ? sensor module type: sensor module will send device descriptor back to master module in this stage. ? sensor module parameter : sensor module will send report descriptor back to master module in this stage. ? parameter t rans action : the master module and sensor modules can trans act parameter to each other, and can be defined as four kinds of types: get input, set out put, get feature and set feature . figure 3 - 2 communication protocol between master and sensor module at the beginning of system operation, the master should identify the sensor module before it can transmit or receive p arameter to/from the sensor modules . the commands and transaction flows that master communicate s with sensor module are explained and show n below . 1. master identif ies the sensor module: call the sensor module by i 2 c, if master receives any response s from the sensor module that it indicates the sensor module is connected. 2. maste r ask s the sensor module to re port its device descriptor ( s tage 1). ex. p arameter length and id master sensor module device descriptor stage 1 : address + command (01) stage 2 : a ddress + command ( 02 ) report descriptor stage 3 : address + command ( 3, 4, 5, and 6 ) parameter information
n umaker brick dec 23 , 201 6 page 29 of 71 rev 1 . 00 nu maker brick design g uide device descriptor : ( command 0x 01 ) start address w ack command ( 0x 01) ack command ( 0x 00) ack sr address r ack tid descriptor ack tid descriptor nack note : also see table 3 - 2 . 3. maste r asks the sensor module respon d to report descriptor ( s tage 2). report descriptor : ( command 0x 0 2 ) start address w ack command ( 0x 02) ack command ( 0x 00) ack sr address r ack report descriptor ack report descriptor nack note: also see table 3 - 3 . 4. maste r asks the sensor module to re port its parameters ( s tage 3). there are four kinds of types : get input , set output , get feature and set feature . get input : ( command 0x 03 ) start address w ack command ( 0x 03) ack command ( 0x 00) ack sr address r data ( l ength f ield , lsb) ack data ( l ength f ield , msb) ack data (report field , l sb) ack data (report field , msb) nack note: also see table 3 - 4 . set output : ( command 0x 04 ) start address w ack command ( 0x 04) ack command ( 0x 00) ack data ( l ength f ield , lsb) ack data ( l ength f ield , msb) ack data (report field , lsb) ack data (report field , msb) ack p note: also see table 3 - 4 . get feature : ( command 0x 05 ) start address w ack command ( 0x 05) ack command ( 0x 00) ack sr address r data ( l ength f ield , lsb) ack data ( l ength f ield , msb) ack data (report field , l sb) ack data (report field , msb) nack note: also see table 3 - 4 . set feature : ( command 0x 06 ) start address w ack command ( 0x 0 6 ) ack command ( 0x 00) ack data ( l ength f ield , lsb) ack data ( l ength f ield , msb) ack data (report field , lsb) ack data (report field , msb) ack p note: also see table 3 - 4 . user can randomly set the length and range of parameter, giving the maximum flexibility for all users .
n umaker brick dec 23 , 201 6 page 30 of 71 rev 1 . 00 nu maker brick design g uide p arameter format 3.2 the m aster module plays the most important role in the whole NUMAKER brick platform. master should identify all the sensor modules on the same i 2 c bus before transacting parameter s with sensor modules. after recognizing all the sensor modules, master will receive parameter s from sensor module s or transmit parameter to sensor module s through the i 2 c bus . 3.2.1 device d escriptor as shown in figure 3 - 2 , i n the stage 1 , the m aster asks the sensor module to pass back the d evice d escriptor , and the parameter length of each parameter is 2 bytes in this device descriptor . master can get the related parameters, for example , the company id, device id, product id, and the hardware version to know the sensor module from the reporting of device de scriptor . table 3 - 2 shows the complete format of device descriptor. data name data content data length function description start flag 257 (1, 1) 2 bytes device descriptor l ength 26 2 bytes first stage (device descriptor) data length report descriptor l ength variable 2 bytes second stage (report descriptor) data length get f eature l e ngth variable 2 bytes third stage (get f eature) data length set f eature l ength variable 2 bytes third stage (set f eature) data length get input l ength variable 2 bytes third stage (get input) data length set output l ength variable 2 bytes third stage (set output) data length company code variable 2 bytes company code which produce sensor module device code variable 2 bytes sensor modules device code product code variable 2 bytes sensor modules product code hardware version variable 2 bytes sensor modules hardware version device c lass code variable 2 bytes sensor modules device reserved variable 2 bytes reserved variable 2 bytes table 3 - 2 device descriptor format 3.2.2 report descriptor as shown in figure 3 - 2 , in the stage 2 , the mas ter asks the sensor module to report the report d escriptor. after confirming each length of class in the sensor module, user s can start get ting the length of every data. in this stage, transfer whole data length first. second, transfer feature data. in feature data, transfer 257 represent following data are feature data and t hen start to transfer single data. the first single data to transfer is address inform ation. ( e.g. 1 st data:5, 2 nd data:17, 3 rd data:29, 4 th data:41, 5 th data:53, 6 th data:65, 7 th data:77, 8 th data:89, 9 th data:101, 10 th data:113,). then data length (usually 1~2 bits) is transferred . at last, maximum (8+1 or 8+2) and minimum (10+1 or 10+2) are transferred.
n umaker brick dec 23 , 201 6 page 31 of 71 rev 1 . 00 nu maker brick design g uide data name data content data length function description report descriptor l ength variable the total data length of r eport d escriptor p arameter c lass ( f eature) 257 (1, 1) 2 bytes declare the following p arameter type: f eature p arameter a ddress 5 1 byte declare this p arameter address (5, 17, 29, 41, 53, 65, 77, 89, 101, 113) p arameter l ength 1~2 1 byte declare this p arameter length (1 ~2 bytes) minimum parameter value 9 or 10 1 byte declare the next column is the minimum parameter value (8) and next column length (1 or 2) minimum parameter value variable 1~2 bytes the minimum parameter value maximum parameter value 13 or 14 1 byte declare the next column is the maximum parameter value (12) and the next column length (1 or 2) maximum parameter value variable 1~2 bytes the maximum parameter value p arameter a ddress 17 1 byte declare this p arameter address (5, 17, 29, 41, 53, 65, 77, 89, 101, 113) p arameter l ength 1~2 1 byte declare the p arameter length (1~2 bytes) minimum parameter value 9 or 10 1 byte declare the next column is the minimum parameter value (8) and next column length (1 or 2) minimum parameter value variable 1~2 bytes the minimum parameter value maximum parameter value 13 or 14 1 byte declare the next column is the maximum parameter value (12) and next column length (1 or 2) maximum parameter value variable 1~2 bytes the maximum parameter value p arameter c lass ( i nput) 258 (1, 2) declare the following p arameter type: i nput p arameter a ddress 5 1 byte declare this p arameter address (5, 17, 29, 41, 53, 65, 77, 89, 101, 113) p arameter l ength 1~2 1 byte declare this p arameter length (1~2 bytes) minimum parameter value 9 or 10 1 byte declare the next column is the minimum parameter value (8) and next column length (1 or 2) minimum parameter value variable 1~2 bytes the minimum parameter value maximum parameter value 13 or 14 1 byte declare the next column is the maximum parameter value (12) and next column length (1 or 2)
n umaker brick dec 23 , 201 6 page 32 of 71 rev 1 . 00 nu maker brick design g uide maximum parameter value variable 1~2 bytes the maximum parameter value p arameter a ddress 17 1 byte declare this p arameter address (5, 17, 29, 41, 53, 65, 77, 89, 101, 113) p arameter l ength 1~2 1 byte declare this p arameter length (1~2 bytes) minimum parameter value 9 or 10 1 byte declare the next column is the minimum parameter value (8) and next column length (1 or 2) minimum parameter value variable 1~2 bytes the minimum parameter value maximum parameter value 13 or 14 1 byte declare the next column is the maximum parameter value (12) and next column length (1 or 2) maximum parameter value variable 1~2 bytes the maximum parameter value p arameter c lass ( o utput) 259 (1, 3) declare the following information type: o utput p arameter a ddress 5 1 byte declare this p arameter address (5, 17, 29, 41, 53, 65, 77, 89, 101, 113) p arameter l ength 1~2 1 byte declare this p arameter length (1~2 bytes) minimum parameter value 9 or 10 1 byte declare the next column is the minimum parameter value (8) and next column length (1 or 2) minimum parameter value variable 1~2 bytes the minimum parameter value maximum parameter value 13 or 14 1 byte declare the next column is the maximum parameter value (12) and next column length (1 or 2) maximum parameter value variable 1~2 bytes the maximum parameter value p arameter a ddress 17 1 byte declare this p arameter address (5, 17, 29, 41, 53, 65, 77, 89, 101, 113) p arameter length 1~2 1 byte declare the p arameter length (1~2 bytes) minimum parameter value 9 or 10 1 byte declare the next column is the minimum parameter value (8) and next column length (1 or 2) minimum parameter value variable 1~2 bytes the minimum parameter value maximum parameter value 13 or 14 1 byte declare the next column is the maximum parameter value (12) and next column length (1 or 2) maximum parameter value variable 1~2 bytes the maximum parameter value table 3 - 3 report descriptor format
n umaker brick dec 23 , 201 6 page 33 of 71 rev 1 . 00 nu maker brick design g uide at this time , the master must s ave the information in the following order: after receiving the p arameter address, the length of p arameter will be store d at corresponding datalen and the arg p arameter also will be updated by the current value . for example, w hen receiving address is 29 and length is 2, write 2 to the third datalen and 3 to the third arg. 3.2.3 p arameter information after master receiv es the r eport d escriptor done from the sensor module , user s can get or set the content values of parameters . there are four kinds of read or write options that correspond to different p arameter type s ( feature, i nput and o utput) . ? write sensor module o utput p arameter ? read sensor module i nput p arameter ? write senso r module f eature p arameter ? read sensor module f eature p arameter data name data content data length function description get feature l ength (set feature l ength) (get input l ength) (set output l ength) variable 2 bytes the total length of data information first p arameter v alue variable 1~2 bytes the first p arameter in the classification s econd p arameter va lue variable 1~2 bytes the second p arameter in the classification ... table 3 - 4 p arameter format the parameter is determined according to the arg parameter at th is stage . if the arg is not zero, it indicates that the parameter is meaningful. if the arg parameter is zero, it indicates that this parameter can be ignored.
n umaker brick dec 23 , 201 6 page 34 of 71 rev 1 . 00 nu maker brick design g uide 4 a dding a new s ensor module t he pr ocedure of adding a new sensor module can be separated into two stages : hardware stage and software stage. on the hardware stage, it is suppose d that user has a workable sensor, for example, the photoresistor sensor . figure 4 - 1 shows how to add the hardware circuit about the photoresist o r sensor on the expansion module board. section 4.2 wil l guide user how to modify the firmware program for this new photo resistor sensor module . figure 4 - 1 expansion module board
n umaker brick dec 23 , 201 6 page 35 of 71 rev 1 . 00 nu maker brick design g uide hardware stage 4.1 the hardware stage includes two steps: setting id for new sensor module and a dding new hardware circuit on e xpansion module b oard . following is an example of adding a photoresistor sensor module. 4.1.1 setting id for new sensor module this chapter migrate s the workable photoresistor sensor circuit to the expansion module board. o n this expansion module board , it provides many through holes (vias) and four 2x6 connectors that one by one mapped to all pin s of mcu to expand the gpio functions of pins and to solder conveniently the extra hardware circuit s . figure 4 - 2 shows the partial schematics of mcu and id checking of this e xpansion m odule b oard . the mcu m452lg6ae chip is one of the m452 series microcontroller s and this chip has very rich peripherals, for example, uart, s mart c ard, spi, i 2 c, i 2 s, usb, pwm, ac m p, dac and adc. figure 4 - 2 p artial s chematics of mcu and id c heck of expansion module board before add ing a new sensor module into the working NUMAKER brick platform , it is very important for user to define the module s id for this new sensor module . the resistor r138 for the id check as sho w n in figure 4 - 2 is a variable resist or for user to change the adc input voltage on the pb.0 pin of m452lg6ae mcu to define the id value for th is new sensor module that created by th e expansion module board . in this example of photoresistor sensor module, t he r esistance value of r138 should be adjusted to 5.1k , the 9 th sensor module (id = 9) , to distinguish with the other sensor modules (id = 0~8) that had been pre - defined in the NUMAKER brick. table 4 - 1 shows the id values from 9 to 14 and their corresponding r esistance value s and adc voltage s that input to pb.0 pin of mcu m452lg6ae if user has the other new sensor modules that will be add ed in the NUMAKER brick platform .
n umaker brick dec 23 , 201 6 page 36 of 71 rev 1 . 00 nu maker brick design g uide id target voltage range resistance value connected to v dd resistance value connected to gnd voltage value 9 1.9v ~ 2.05v 3.3k 5.1k 1.99v 10 2.1v ~ 2.25v 3.3k 6.8k 2.2v 11 2.3v ~ 2.45v 3.3k 9.1k 2.41v 12 2.5v ~ 2.65v 3.3k 12k 2.59v 13 2.7v ~ 2.85v 3.3k 18k 2.8v 14 2.9v ~ 3.05v 3.3k 33k 3v table 4 - 1 id identifying by different resistan ce and adc voltage for new sensor module 4.1.2 adding new hardware circuit on expansion module board after settin g the resistance value of r138 for the id check, user can add additional photoresistor sensor circuit on the expansion module board , and t hen connect the power required by the module and the pin that needs to be connected to the mcu to the appropriate connector . figure 4 - 3 shows the complete schematic diagram of th e new photoresistor sensor module. figure 4 - 3 complete schematic diagram of new photoresistor sensor module
n umaker brick dec 23 , 201 6 page 37 of 71 rev 1 . 00 nu maker brick design g uide software stage 4.2 th e s oftware stage can be separated into two section s, program initialization and program execution. table 4 - 2 shows that s o ftware should be modified or added on to both master module and new sensor module. at program initialization, user doesnt need to modify any programs for the master module, but for the new sensor module user should first identify the id , and then do hardware initialization for this new sensor module and define the related parameters for the numake r brick platform. at program execut ion , user should add the response program in to the master module for the new sensor module due to this sensor module joining and add the main execution program into the new sensor module. software section master module new sensor m odule initializ ation it lr_init and the periodic execution function - call getlr as shown in figure 4 - 4 . apfn_ func_t pfndevfunc[max_tid_dev] = { /* functions for each device: {initial, period, pulling, report} initial : init and configure device period : process device sensor parameter or set sensor once per 0.1 seconds. p o lling : process device sensor parameter or set sensor frequently. report : report process parameter to master */ /* for embedded device boards */
n umaker brick dec 23 , 201 6 page 38 of 71 rev 1 . 00 nu maker brick design g uide {battery_init, mastercontrol, null, report_battery}, {buzzer_init , null, buzzer_control, report_buzzer}, {led_init, null, led_control, report_led}, {ahrs_init, ahrs_control, ahrs_cal, report_ahrs}, {sonarinit, sonardetect, sonartimeoutch eck, report_sonar}, {htu21d_init, waithtu21d, gethtu21dtemp, report_temp}, {gas_init, getgas, null, report_gas}, {ir_init, ir_control, ir_check, report_ir}, {key_init, null, null, report_key}, /* for custom device boards fill your four board functions here to specified id. */ { lr_init, getlr, null, report_resdev9}, // for device id 9 {null, null, null, report_resdev10}, // for device id 10 {null, null, null, report_resdev11}, // for device id 11 {null, null, null, report_resdev12}, // for device id 12 {null, null, null, report_resdev13}, // for device id 13 {null, null, null, report_resdev14} // for device id 14 }; figure 4 - 4 function - calls of new sensor module in modular programming table 4.2.1 program initialization section figure 4 - 5 shows the program initialization of photoresistor sensor module, the lr_init() function - call. t he program initialization includes adc hardware initialization based on the new photoresistor sensor module and set ting the related parameters including device descriptor and report descriptor , which will be transacted between master module and this new sensor module. t he report de scriptor includes three types of classified parameters about this new photoresistor sensor module : feature, input and output classes . there are four parameters about this new photoresistor sensor module that should be transacted with master module, the sleeping p eriod, a larm t rigger v alue, l ight v alue and a larm f lag that are put in the feature and input classes individually . for e ach parameter , user also needs to define the maximum value , minimum value , content of parameter , position of parameter , lengt h of parameter and number of parameter for each parameter i n individual class. ? m aximum and m inimum: s et by the required parameter. ? value: the current parameter value . ? arg: the position of parameter , i ncreasing by one . ? datalen: the length of parameter , the unit is byte. ? datanum: the total number of parameter in this class. sensor f unction execute d period ical ly sensor f unction execute d immediately sensor m odule s initializ ation
n umaker brick dec 23 , 201 6 page 39 of 71 rev 1 . 00 nu maker brick design g uide void lr_init() { sys_unlockreg(); /* enable eadc module clock */ clk_enablemoduleclock(eadc_module); /* eadc clock source is 72mhz, set divider to 8, adc clock is 72/8 mhz */ clk_setmoduleclock(eadc_module, 0, clk_clkdiv0_eadc(8)); sys_lockreg(); /* configure the gpb0 - gpb3 adc anal og input pins */ sys - >gpb_mfpl &= ~sys_gpb_mfpl_pb1mfp_msk; sys - >gpb_mfpl |= sys_gpb_mfpl_pb1mfp_eadc_ch1; gpio_disable_digital_path(pb, bit1); /* set the adc internal sampling time, input mode as single - end and enable the a/d converter */ eadc_open(eadc, eadc_ctl_diffen_single_end); eadc_setinternalsampletime(eadc, 6); /* configure the sample module 0 for analog input channel 1 and software trigger source.*/ eadc_configsamplemodule(eadc, 1, eadc_software_trigger, 1); /* clear the a/d adint0 interrupt flag for safe */ eadc_clr_int_flag(eadc, 0x2); /* enable the sample module 0 interrupt. */ eadc_enable_int(eadc, 0x2); //enable sample module a/d adint0 interrupt eadc_enable_sample_module_int(eadc, 1, 0x2); //enable sample module 0 interrupt. resdev9.devdesc.devdesc_leng = 26; //report descriptor resdev9.devdesc.rptdesc_leng = 36; //report descriptor resdev9.devdesc.inrptleng = 5; //input report resdev9.devdesc.outrptleng = 0; //output report resdev9.devdesc.getfeatleng = 6; //get fea ture resdev9.devdesc.setfeatleng = 6; / /set feature resdev9.devdesc.cid = 0; //manufacturers id resdev9.devdesc.did = 0; //product id resdev9.devdesc.pid = 0; //device firmware revision resdev9.devdesc.uid = 0; //device class type resdev9.devdesc.ucid = 0; //reserve device descriptor i niti aliz ation of sensor module s ettings of sensor module will be passed to master module
n umaker brick dec 23 , 201 6 page 40 of 71 rev 1 . 00 nu maker brick design g uide /* feature */ resdev9.feature.data1.minimum = 0; //sleep period resdev9.feature.data1.maximum = 1024; resdev9.feature.data1.value = 100; resdev9.feature.data2.minimum = 0; // photo resist or al a rm value resdev9.feature.data2.maximum = 100; resdev9.feature.data2.value = 20; resdev9.feature.arg[0] = 1; resdev9.feature.arg[1] = 2; resdev9.feature.datalen[0] = 2; resdev9.feature.datalen[1] = 2; resdev9.feature.datanum = 2; /* input */ resdev9.input.data1.minimum = 0; // photo resist or value resdev9.input.data1.maximum = 100; resdev9.input.data1.value = 100; resdev9.input.data2.minimum = 0; //over flag resdev9.input.data2.maximum = 1; resdev9.input.data2.value = 0; resdev9.input.arg[0] = 1; resdev9.input.arg[1] = 2; resdev9.input.datalen[0] = 2; resdev9.input.datalen[1] = 1; resdev9.input.datanum = 2; /* output */ resdev9.output.datanum = 0; } figure 4 - 5 photo r esistor sensing module initializ ation program at this t ime , a new sensor module initialization is completed . t hen , proceed to the execution phase. 4.2.2 program execution section the execution stage can be divided into two parts : ? sensor module modification : add original program into NUMAKER brick platform ? master program modification : the modif ication of the maste r is to communicate with new module s. the communication includes s et ting the objects that can be triggered by a new device , a nd the object that can trigger the new device. at tidmstupdatedevstate(), which is in tismst. c . feature input output s leep p eriod trigger alarm vaule p arameter position p arameter length p arameter number p arameter position p arameter length p arameter number sensor value alarm flag
n umaker brick dec 23 , 201 6 page 41 of 71 rev 1 . 00 nu maker brick design g uide the functions of the photoresistor module used in this program are described as follows: i f the parameter that photoresistor module sends back is 1 ; 1. i f a buzzer and the photoresis tor module are related to each other ; 2. m aster asks the buzzer starts to beep ; 3. i f the led and photoresistor module are related to each other ; 4. m aster asks the led to start to blink . // ******************************************************* // master handle device state // ******************************************************* void tidmstupdatedevstate() { ... else if((resdev9.input.data2.value == 1) && (tidmstinitdevstate & (1< n umaker brick dec 23 , 201 6 page 42 of 71 rev 1 . 00 nu maker brick design g uide 5 n umaker b rick connected with arduino user can also use arduino as a new sensor module to connect with the NUMAKER brick . the procedure can be separated into two step s as described in the following sections . the first section will discuss the necessary program s that all sensor modules should execute. the second section will describe how to add the new arduino module into NUMAKER brick platform. necessary function - calls for all sensor module s 5.1 th is s ection introduces the necessary program function - calls of setup() and loop() that all sensor module s in the NUMAKER brick platform should execute . 5.1.1 fun ction - c all setup () as shown in figure 5 - 1 , there are three steps in the initializ ation program in the function - call setup() for any sensor module s . 1. set uart: set the uart module and its baud rate . 2. i 2 c initialization: set the i 2 c pin and it s bit rate . 3. save the module parameter to the variables that will be trans acted by i 2 c bus . void setup() { . . . serial_begin ( 9600 ); i 2c _init(); le d _init (); slvdevinit(&leddev); slvdatastore(); . . . } figure 5 - 1 initializ ation program of setup () for all sensor module s 5.1.2 function - call l oop () as shown in figure 5 - 2 , in the function - call loop () the following steps need to be completed for any of the sensor module s . 1. arrange and handle the p arameter received from master. 2. save p arameter into the variable s that will be transacted with master module by i 2 c bus . 2. i 2 c initialization 1. set uart port 3. s ave module parameter into variable s that will be transacted by i 2 c bus
n umaker brick dec 23 , 201 6 page 43 of 71 rev 1 . 00 nu maker brick design g uide void loop() { . . . tid_slvrxupdate() ; /* led code */ if( leddev.output.data2.value==0) { i f(leddev.output.data1.value == 1) { led_blink_start(); leddev.output.data1.value=0; } } else { led_stop(); } led_blink_check(); //update tid parameter slvdatastore(); . . . } figure 5 - 2 program execution of loop() for all sensor module s arrange and handle the parameter received from master save parameter into the variable s that will be transacted by i 2 c bus
n umaker brick dec 23 , 201 6 page 44 of 71 rev 1 . 00 nu maker brick design g uide adding a new arduino module 5.2 5.2.1 hardware stage in the example of adding a new arduino module, arduino mega is used to implement as a new sensor module when it connects with the arduino rgb led module. i n figure 5 - 3 , these three r , g and b connectors on the arduino mega should be connected with the pins that have the same name on the arduino rgb led module to control the display color of led . the sda and scl connectors on the arduino mega are the i 2 c interface that should be connect ed to the NUMAKER brick platform . finally, the ground of arduino mega shou l d also be connected with the ground of NUMAKER brick for the common ground . note: when the NUMAKER brick is connect ed with th e new arduino led sensor module , the original led sensor module that belo ngs to the NUMAKER brick must be removed from th e NUMAKER brick platform. figure 5 - 3 schematic diagram of arduino mega and arduino rgb led module 5.2.2 software stage when adding a new arduino module, two parts of software should be modified : setup () and loop() function - calls . ? function - call s etup () : the new program ( led initialization ) inside setup() function - call for the arduino module is almost the same as the original program of the led sensor module in NUMAKER brick platform , as shown in figure 5 - 4 . r g b 3 . 3 v 3 . 3 v g n d b r g s d a s c l
n umaker brick dec 23 , 201 6 page 45 of 71 rev 1 . 00 nu maker brick design g uide void setup() { . . . serial_begin ( 9600 ); i 2c _init(); le d _init (); slvdevinit(&leddev); slvdatastore(); . . . } figure 5 - 4 led initialization program in setup() for arduino led module ? function - call loop(): the loop () function - call can be separat ed into two parts : ? program execut ed period ic ally : i t is not necessary to modify any programs for the arduino led module . ? program executed non - periodically : to create the n on - p eriod ic execution programs as shown in figure 5 - 5 for the arduino led module. led initialization
n umaker brick dec 23 , 201 6 page 46 of 71 rev 1 . 00 nu maker brick design g uide void loop() { . . . tid_slvrxupdate() ; /* led code */ if(leddev.output.data2.value==0) { i f( leddev.output.data1.value == 1) { led_blink_start(); leddev.output.data1.value=0; } } else { led_stop(); } led_blink_check(); //update tid parameter slvdatastore(); . . . } figure 5 - 5 led execution program in loop() for arduino led module non - p eriod ic execution program
n umaker brick dec 23 , 201 6 page 47 of 71 rev 1 . 00 nu maker brick design g uide 6 a ppendix a - app d esign c oncept the whole platform consists of a master modul e and some sensor modules, and thus user needs to set different parameters for different situations , f or example, the humidity alarm value and the sonar alarm distance. it is very tedious when there is a little change in this whole platform and it requires users to re - program all the flash e s of chips on the whole platform system . so planning to design the app can communicate with the master and command the master to modify the p arameter of the sensor module which will be greatly improved the convenience of the user. . there are three main pages that can be selected on app: ? index p age: user can briefly understand the p arameter or status of each sensor module and set the connection port on this page. ? device link p age: user can easily set the relationship s between each sensor module. ? sensor m odule p age: user can see the detailed p arameter or status on each sensor module. the app is communicat ed with the master module through the uart interface . some basic commands that app can send to master are listed below: 1. start to send data: @ss 2. stop sending data: @sp 3. set transmission format: @tx the following sections will introduce some additional features.
n umaker brick dec 23 , 201 6 page 48 of 71 rev 1 . 00 nu maker brick design g uide index page 6.1 figure 6 - 1 shows the i ndex page on app . this page has two main function s : ? to d isplay how many sensor modules those are connected at the moment to ma ster module. ? to d isplay the current i nput p arameter from each sensor module. t he following describe s how the master module communicate s the two kinds of p arameter s mentioned above with sensor modules . the data length is two bytes for each data . figure 6 - 1 i ndex page t he transmission process on maser module for th is index page can be classif ied into two stage s: ? to t ransmit how many sensor module s are connected to the master module . ? t o t ransmit the p arameter that received from each sensor module . if there are any errors occur under transmission, the transmission stage will be back to stage 1 to reconfirm the status of connection b e t w een the master module and sensor modules . the transmiss ion command s used to switch to th e index page on app are listed below in sequence: 1. send @tx, to request master to send the information on i ndex page 2. send @ss, to request master to start to send information 3. s end @sp , to request master to stop sending data if there are any errors occur 4. send @tx, to request master to switch to th is page again 5. w ait 500 ms 6. send @ss, to request master to start to send information
n umaker brick dec 23 , 201 6 page 49 of 71 rev 1 . 00 nu maker brick design g uide the f ollowing describes the r eport d escriptor that app receive s from the master module. table 6 - 1 lists the data format that app received in the first stage of index page . d ata n ame d ata c ontent d ata l ength description inform s tart f lag 257 (1 , 1) 2 bytes s tart to transmit data first s tage d ata l ength 8 2 bytes there are total 4 data in the first stage, 8 bytes sensor m odule n umber 8 2 bytes the t otal number of sensor module s connected m odule n umber variable 2 bytes the n umber of sensor module s that connected second st age d ata l ength 30 2 bytes there are total 15 data in the second stage , 30 bytes table 6 - 1 d ata format that app receiv ed in the first s tage of index page after the forth data ( connected module number ) is receiv ed and handled , user can get the status of link to device from the icons that are turned on or turned off on this app index page . from the analyzing of the forth data, t he 1 st bit is the indbattery and the battery icon on the app index page will be turned on if this bit is 1 . t he 2 nd bit is the indbuzzer and the buzzer icon on the app index page will be turned on if this bit is 1 . t he 3 rd bit is the indled and the led icon on the app index page will be turned on if this bit is 1 . t he 4 th bit is the indahrs and the ahrs icon on the app index page will be turned on if this bit is 1. t he 5 th bit is the indsonar and the sonar icon on the app index page will be turned on if this bit is 1 . t he 6 th bit is the i ndtemp and the temperature icon on the app index page will be turned on if this bit is 1 . the 7 th bit is the indgas and the gas icon on the app index page will be turned on if this bit is 1 . t he 8 th bit is the indir and the ir icon on app index page will be turned on if this bit is 1 . the 5 th received data are used to confirm the received data whether are correct in the second stage . this procedure of stage 1 will re - start i f any errors occur during transmission . table 6 - 2 lists the data format that app received in the second stage of index page . d ata n ame d ata c ontent d ata l ength description second s tage d ata l ength 30 2 bytes to re - start stage 1 if the value is not 30 battery v alue variable 2 bytes low p ower a larm variable 2 bytes 1 indicates the low power state buzzer s tat us variable 2 bytes 1 indicates the buzzer is working led s t at us variable 2 bytes 1 indicates the led is working vibration val ue variable 2 bytes vibration a larm variable 2 bytes 1 indicates the vibration alarm is triggered sonar valu e variable 2 bytes
n umaker brick dec 23 , 201 6 page 50 of 71 rev 1 . 00 nu maker brick design g uide distance al arm variable 2 bytes 1 indicates the distance alarm is triggered temperature variable 2 bytes humidity variable 2 bytes temperature a larm variable 2 bytes 1 indicates the temperature alarm is triggered humidity a larm variable 2 bytes 1 indicates the humidity alarm is triggered gas v alue variable 2 bytes gas a larm variable 2 bytes 1 indicates the gas alarm is triggered table 6 - 2 d ata format that app receiv ed in the second s tage of index page
n umaker brick dec 23 , 201 6 page 51 of 71 rev 1 . 00 nu maker brick design g uide device link p age 6.2 figure 6 - 2 shows the device link p age on app and the link relationships between each sensor module. the sensor module s can be classified in to two type s : the input type ( b attery, vibration, sonar, temperature and gas modules ) and the output type ( buzzer and led modules ). t he transmission process on the device link page can be separated into two stage s : ? to d isplay the sensor module s that connect ed to master module . ? to d ispla y the link relationship s between each sensor module. the two stages are classified into three aspects : ? to d isplay the sensor modules those are currently connected to the NUMAKER brick platform . ? to di splay the sensor module's relationship to each other . ? to r e ceive the sensor module's relationship between each other without updating . the transmission commands used to switch to th e device link page on app are listed below in sequence : 1. send @td: to request master to send information on d evice l ink page 2. send @ss: to request master to start to send information 3. send @sp: to request master to stop sending data if there are any errors occur 4. send @tx: to request master to switch to this page again 5. w ait 500 ms 6. send @ss: to request master to start to send information figure 6 - 2 device link p age
n umaker brick dec 23 , 201 6 page 52 of 71 rev 1 . 00 nu maker brick design g uide t he receiv ed data is shown below : table 6 - 3 lists the data format that app received in the first stage of device link page. d ata n ame d ata c ontent d ata l ength description inform s tart f lag 257 (1 , 1) 2 bytes s tart to transmit data first s tage d ata l ength 8 2 bytes there are total 4 data in the first stage, 8 bytes sensor m odule n umber 8 2 bytes the t otal number of sensor module s c onnected s ensor m odule n umber variable 2 bytes the number of sensor module s that connected s econd s tage d ata l ength 6 2 bytes there are total 3 data in the second stage , 6 bytes table 6 - 3 data format that app received in the first stage of d evice link p age s imilar to the i ndex page , t he 4 th data is used to confirm the status of sensor modules which are currently connected to the platform . t he fi fth received data are used to confirm the data length in second and the third stage s of device link page . table 6 - 4 lists the data format that app received in the second stage of device link page. d ata n ame d ata c ontent d ata l ength description second s tage d ata l ength 6 2 bytes to re - start to stage 1 if this value is not 6 connection s tat us between b uzzer and the o ther modules variable 2 bytes n/a connection s tat us between led and the o ther modules variable 2 bytes n/a table 6 - 4 data format that app received in the second stage of device link page the main purpose of the second stage is to show that the b uzzer and led can be controlled by which sensor module (1 indicates that their relationships are connected with each other and the icons will be turned on ) . the 1 st bit of the received second data for the buzzer module indicates the link relationship with the battery sensor modul e . the 2 nd and 3 rd b it s are skipped out . the 4 th bit indicates the link relationship between the buzzer module and vibrat ion module . the 5 th bit indicates the link relationship between the buzzer module and sonar module . the 6 th bit indicates the link relationship between the buzzer module and the temperature and humidity module . the 7 th bit indicates the link relation ship between the buzzer module and gas module . the meaning of bits of the received third data for led module is the same as that for the buzzer module . the information data received in third stage is exactly the same as that in the second stage . but the difference is that it does not need to update the display stat us in the third stage. user can click the reload button on th is page to update the last display status . this is b ecause the app cannot achieve to transact the data with master module and update the status on this page at the same time . the transmission processing is shown below and can be separated into two parts: reload and set.
n umaker brick dec 23 , 201 6 page 53 of 71 rev 1 . 00 nu maker brick design g uide t here are two steps in the r eload stage the master module requested by the @ss command to transmit the values continuously a nd to update the display stat us . because it just only to receive the value s but not to update the display s tat us in the third stage . it is provided to update the display status without switchin g any the page s . the set stage is to change the link stat us of master module with the sensor module s wh en there are setting change s on the app by users, the app will send c ommand s to the master module and the master module will reconnect to these sensor modules by th is new link commands . table 6 - 5 shows the commands supported in the set stage. transfer data description @mz40+1or0+ r @mz43+1or0+ r @mz44+1or0+ r @mz45+1or0+ r @mz46+1or0+ r @ml40+1or0+ r @ml43+1or0+ r @ml44+1or0+ r @ml45+1or0+ r @ml46+1or0+ r
n umaker brick dec 23 , 201 6 page 54 of 71 rev 1 . 00 nu maker brick design g uide sensor m odule p age 6.3 t here are a total of seven pages for the sensor module s (battery , buzzer , led , vibration, sonar, temperature and gas ) on the app . e ach sensor module page is used to : ? d isplay the information of sensor module ; and ? m odify the data of sensor module t here are three type s of each sensor module s data: i nput, o utput and f eature. in this chapter, the types are s implified into two type s : the control type ( o utput and f eature) and the state type ( i nput). t he data of input cannot be modified by user so it is classifie d as the state type . but u ser can modify the data of both o utput and f eature can be modified so they are c lassifie d as the control type. the data of each sensor module can be classified into four steps : 1. g et d evice d escript or 2. get r eport d escriptor 3. get data information 4. get data information but only update the data of state type the transmission command s used to switch the sensor module page are listed below in sequence : 1. send @tb(*) , to request master to send information on the sensor ( @ tb is for battery) module s page 2. send @ss , to request master to start to send information 3. send @sp , to request master to stop sending data if there are any errors occur 4. send @tx , to request master to switch to this page again 5. w ait 500 ms 6. send @ss , to request master to start to send information (*): the other commands for sensor modules are listed below: sensor module order battery @tb b uzzer @tz led @tl vibration @ta sonar @ts temperature @tt g as @tg table 6 - 6 command s to s witch to sensor m odule p age the buzzer module page is shown in figure 6 - 3 . i ts data can be simplified in to two type s : control type ( o utput and f eature) and state type ( i nput).
n umaker brick dec 23 , 201 6 page 55 of 71 rev 1 . 00 nu maker brick design g uide figure 6 - 3 buzzer module p age there are three stage s for the receiv ed data from the sensor module . the first st age is to get the d evice d escriptor from the sensor module. if the first byte of the received d ata is not equal to 25 7 , it indicates that the data ha s error s for the app . table 6 - 7 lists the data format of received data from the sensor module in the first stage . d ata n ame d ata c ontent d ata l ength inform s tart f lag 257 (1 , 1) 2 bytes d evice d escript or l ength 26 2 bytes report d escripto r l ength variable 2 bytes g et f eature l ength variable 2 bytes s et f eature l ength variable 2 bytes g et input l ength variable 2 bytes s et output l ength variable 2 bytes c ompany c ode 0 2 bytes
n umaker brick dec 23 , 201 6 page 56 of 71 rev 1 . 00 nu maker brick design g uide device c ode 0 2 bytes product c ode 0 2 bytes firmware v ersion 0 2 bytes device c lass c ode 0 2 bytes reserved 0 2 bytes reserved 0 2 bytes table 6 - 7 receiv ed d ata o n sensor m odule p age in the first stage the second st age is to receive the report d escriptor from the sensor module . after receiv ing the p arameter address, the p arameter length will be saved in the corresponding datalen category variables and writes the current value to arg variables . for example, t he received address is 41 and its length is 1, write the fourth data len variable to 1 and write the arg variable to 4 ). if the first byte of the received data in the second stage is not equal to the length of r eport d escription received in the first stage, it means that there are some error s in side the received data in th is second stage . table 6 - 8 lists the data format of received data from the senso r module in the second stage . data n ame data c ontent data l ength function d escription report descripto r l ength variable t he total length at this stage. parameter c lass ( f eature) 258(1 , 2) declare the following information type: f eature parameter a ddress 5 1 byte declare th e p arameter address (5 , 17 , 29 , 41 , 53 , 65 , 77 , 89 , 101 , 113) parameter l ength 1~2 1 byte declare th e p arameter length (1~2 bytes) m inimum parameter value 9 or 10 1 byte declare the next column is t he minimum value of the data (8) and next column length (1 or 2) m inimum parameter value v ariable 1~2 bytes the minimum parameter value m aximum parameter value 13 or 14 1 byte declare the next column is the maximum value of the data (12) and next column length (1 or 2) m aximum parameter value v ariable 1~2 bytes the m aximum parameter value parameter a ddress 5 1 byte declare th e p arameter address (5 , 17 , 29 , 41 , 53 , 65 , 77 , 89 , 101 , 113) parameter l ength 1~2 1 byte declare this p arameter length( 1 ~2 bytes) m inimum parameter value 9 or 10 1 byte declare the next column is t he minimum value of the data (8) and next column length (1 or 2) m inimum parameter value v ariable 1~2 bytes the minimum parameter value m aximum parameter value 13 or 14 1 byte declare the next column is the maximum value of the data (12) and next column length (1 or 2) m aximum parameter value v ariable 1~2 bytes the m aximum parameter value
n umaker brick dec 23 , 201 6 page 57 of 71 rev 1 . 00 nu maker brick design g uide p arameter c lass ( i nput) 258(1 , 2) declare the following information type: i nput p arameter a ddress 5 1 byte declare th e p arameter address (5 , 17 , 29 , 41 , 53 , 65 , 77 , 89 , 101 , 113) p arameter l ength 1~2 1 byte declare th e p arameter length (1~2 bytes) m inimum parameter value 9 or 10 1 byte declare the next column is t he minimum value of the data (8) and next column length (1 or 2) m inimum parameter value v ariable 1~2 bytes the minimum parameter value m aximum parameter value 13 or 14 1 byte declare the next column is the maximum value of the data (12) and next column length (1 or 2) m aximum parameter value v ariable 1~2 bytes the m aximum parameter value p arameter a ddress 5 1 byte declare th e p arameter address (5 , 17 , 29 , 41 , 53 , 65 , 77 , 89 , 101 , 113) p arameter l ength 1~2 1 byte declare th e p arameter length( 1 ~2 bytes) m inimum parameter value 9 or 10 1 byte declare the next column is t he minimum value of the data (8) and next column length (1 or 2) m inimum parameter value v ariable 1~2 bytes the minimum parameter value m aximum parameter value 13 or 14 1 byte declare the next column is t he maximum value of the data (12) and next column length (1 or 2) m aximum parameter value v ariable 1~2 bytes the maximum parameter value p arameter c lass ( o utput) 258(1 , 2) declare t he following information type: o utput p arameter a ddress 5 1 byte declare th e p arameter address (5 , 17 , 29 , 41 , 53 , 65 , 77 , 89 , 101 , 113) p arameter l ength 1~2 1 byte declare th e p arameter length (1~2 bytes) m inimum parameter value 9 or 10 1 byte declare the next column is t he minimum value of the data (8) and next column length (1 or 2) m inimum parameter value v ariable 1~2 bytes the minimum parameter value m aximum parameter value 13 or 14 1 byte declare the next column is t he maximum value of the data (12) and next column length (1 or 2) m aximum parameter value v ariable 1~2 bytes the maximum parameter value p arameter a ddress 5 1 byte declare th e data address (5 , 17 , 29 , 41 , 53 , 65 , 77 , 89 , 101 , 113) p arameter l ength 1~2 1 byte declare th e p arameter length (1~2 bytes) m inimum parameter value 9 or 10 1 byte declare the next column is t he minimum value of the data (8) and the next column length (1 or 2)
n umaker brick dec 23 , 201 6 page 58 of 71 rev 1 . 00 nu maker brick design g uide m inimum parameter value v ariable 1~2 bytes the minimum parameter value m aximum parameter value 13 or 14 1 byte declare the next column is the maximum value of the data (12) and next column length (1 or 2) m aximum parameter value v ariable 1~2 bytes the maximum parameter value table 6 - 8 receiv ed d ata o n sensor m odule p age in the second stage t he third stage is to receive all the control and stat e typ es ( i nput, o utput and f eature class es ) at one time . if the 1 st data of the received data in the third stage is not equal to the sum of "get input l ength" , "set output l ength" and "get f eature l ength" received in the first stage , it means that there are some error s in side the received data in th e third stage . it is j udg ed based on the value of arg variable of the p arameter . if the value of arg variable is not equal to zero, it means that the data is meaningful . if the value of arg variable is equal to zero , it means that it is ended . table 6 - 9 lists the data format of re ceived data from sensor module in the third stage . data n ame data c ontent data l ength description inform s tart f lag variable 2 bytes the sum of get f eature l ength , set o utput l ength and get i nput l ength that received in the first stage f irst f eature p arameter v alue v ariable 1~2 b ytes second f eature p arameter v alue v ariable 1~2 b ytes variable 1~2 bytes it is decided whether to end by the f irst i nput p arameter v alue variable 1~2 bytes second i nput p arameter v alue variable 1~2 bytes variable 1~2 bytes it is decided whether to end by the arg variable. f irst o utput p arameter v alue variable 1~2 bytes second o utput p arameter v alue variable 1~2 bytes variable 1~2 bytes it is decided whether to end by the arg variable. battery) modules page 3. w ait for 500 ms 4. send @ss, to request master to start to send information
n umaker brick dec 23 , 201 6 page 59 of 71 rev 1 . 00 nu maker brick design g uide the link status of the sensor module is changed by the app and it will be transmitted to the master module . the master will follow these commands to re - connect with the sensor modules by the new link stat us . table 6 - 10 lists the updating commands of app for master module to update the rela t ed parameter of sensor module. (*) : the other commands for sensor modules are shown in table 6 - 11 : transfer c ommand d escription @m*10+data+ r @m*11+data+ r it is decided whether to end by the arg variable. @m*20+data+ r @m*21+data+ r it is decided whether to end by the arg variable. @m*30+data+ r @m*31+data+ r it is decided whether to end by the arg variable. sensor m odule c ommand battery @mb b uzzer @mz led @ml vibration @ma sonar @ms temperature @mt g as @mg table 6 - 11 c ommand s for m odify ing each sensor m odule p arameter
n umaker brick dec 23 , 201 6 page 60 of 71 rev 1 . 00 nu maker brick design g uide 7 a ppendix b - sensor m odule parameter information t he transaction parameter between master an d sensor module s can be separated into three parts: ? device descriptor ? report descriptor ? p arameter information the parameter of e ach module can be separat ed into two par t s : d evice d escription and parameter . p arameter can be classified into three classes : f eature, o utput and i nput. t here are seven sensor modules: battery, buzzer, led, vibration , sonar, temperature and humidity, and gas in the original NUMAKER brick platform . the following tables list the parameters for each sensor module , includ ing the d evice d escriptor, o utput, i nput and f eature. t he value s of brackets inside the m aximum and m inimum cell s of the tables represent the maximum or minimum parameter of the next frame.
n umaker brick dec 23 , 201 6 page 61 of 71 rev 1 . 00 nu maker brick design g uide b attery m odule 7.1 d ata n ame d ata c ontent d ata l ength i 2 c a ddress 20 2 bytes device d escript or d ata l ength 26 2 bytes report d escript or d ata l ength 36 2 bytes get i nput d ata l ength 5 2 bytes set o utput d ata l ength 0 2 bytes get f eature d ata l ength 6 2 bytes set f eature d ata l ength 6 2 bytes company c ode 0 2 bytes device c ode 0 2 bytes product c ode 0 2 bytes firmware v ersion 0 2 bytes device c lass c ode 0 2 bytes reserved 0 2 bytes reserved 0 2 bytes table 7 - 1 d evice d escriptor of battery m odule d ata n ame d ata a ddress d ata l ength m inimum ( position ) m aximum ( position ) sleep p eriod 5 2 bytes 0 ms (10) 1024 ms (14) low b attery a larm v alue 17 2 bytes 0 % (10) 100 % (14) table 7 - 2 f eature p arameter of battery m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) battery v alue 5 2 bytes 0 (10) 1024 (14) low b attery a larm f lag 17 2 bytes 0 (9) 100 % (14) table 7 - 3 i nput parameter of battery m odule
n umaker brick dec 23 , 201 6 page 62 of 71 rev 1 . 00 nu maker brick design g uide b uzzer m odule 7.2 d ata n ame d ata c ontent d ata l ength i 2 c a ddress 21 2 bytes device d escript or d ata l ength 26 2 bytes report d escript or d ata l ength 74 2 bytes get i nput d ata l ength 3 2 bytes set o utput d ata l ength 4 2 bytes get f eature d ata l ength 12 2 bytes set f eature d ata l ength 12 2 bytes company c ode 0 2 bytes device c ode 0 2 bytes product c ode 0 2 bytes firmware v ersion 0 2 bytes device c lass c ode 0 2 bytes reserved 0 2 bytes reserved 0 2 bytes table 7 - 4 d evice d escriptor of buzzer m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) sleep p eriod 5 2 bytes 0 ms (10) 2048 ms (14) v olume 17 1 byte 0 % (9) 100 % (13) f requency 29 2 bytes 0 hz (10) 5000 hz (14) song 41 1 byte 0 (9) 2 (13) period 53 2 bytes 0 ms (10) 2048 ms (14) d uty 65 1 byte 0 % (9) 100 % (13) alarm t ime 77 1 byte 0 s (9) 60 s (13) table 7 - 5 f eature parameter of buzzer m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) executing f lag 5 1 byte 0 (9) 1 (13) table 7 - 6 i nput parameter of buzzer m odule
n umaker brick dec 23 , 201 6 page 63 of 71 rev 1 . 00 nu maker brick design g uide parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) s tart executing f lag 5 1 byte 0 (9) 1 (13) stop executing f lag 17 1 byte 0 (9) 1 (13) table 7 - 7 o utput parameter of buzzer m odule
n umaker brick dec 23 , 201 6 page 64 of 71 rev 1 . 00 nu maker brick design g uide led m odule 7.3 d ata n ame d ata c ontent d ata l ength i 2 c a ddress 22 2 bytes device d escript or d ata l ength 26 2 bytes report d escript or d ata l ength 74 2 bytes get i nput d ata l ength 3 2 bytes set o utput d ata l ength 4 2 bytes get f eature d ata l ength 12 2 bytes set f eature d ata l ength 12 2 bytes company c ode 0 2 bytes device c ode 0 2 bytes product c ode 0 2 bytes firmware v ersion 0 2 bytes device c lass c ode 0 2 bytes reserved 0 2 bytes reserved 0 2 bytes table 7 - 8 d evice d escriptor of led m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) sleep p eriod 5 2 bytes 0 ms (10) 1024 ms (14) light 17 1 byte 0 % (9) 100 % (13) color 29 2 bytes 0 (10) 2048 (14) blink 41 1 byte 0 (9) 2 (13) period 53 2 bytes 0 ms (10) 2048 ms (14) duty 65 1 byte 0 % (9) 100 % (13) alarm t ime 77 1 byte 0 s (9) 6 0 s (13) table 7 - 9 feature parameter of led m odule
n umaker brick dec 23 , 201 6 page 65 of 71 rev 1 . 00 nu maker brick design g uide parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) executing f lag 5 1 byte 0 (9) 1 (13) table 7 - 10 i nput parameter of led m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) start executing f lag 5 1 byte 0 (9) 1 (13) stop executing f lag 17 1 byte 0 (9) 1 (13) table 7 - 11 o utput parameter of led m odule
n umaker brick dec 23 , 201 6 page 66 of 71 rev 1 . 00 nu maker brick design g uide v ibration m odule 7.4 d ata n ame d ata c ontent d ata l ength i 2 c a ddress 23 2 bytes device d escript or d ata l ength 26 2 bytes report d escript or d ata l ength 34 2 bytes get i nput d ata l ength 5 2 bytes set o utput d ata l ength 0 2 bytes get f eature d ata l ength 5 2 bytes set f eature d ata l ength 5 2 bytes company c ode 0 2 bytes device c ode 0 2 bytes product c ode 0 2 bytes firmware v ersion 0 2 bytes device c lass c ode 0 2 bytes reserved 0 2 bytes reserved 0 2 bytes table 7 - 12 d evice d escriptor of vibration m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) sleep p eriod 5 2 bytes 0 ms (10) 1024 ms (14) vibration a larm v alue 17 1 byte 0 % (9) 10 (13) table 7 - 13 feature parameter of vibration m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) vibration v alue 5 2 bytes 0 (10) 720 vibration a larm f lag 17 1 byte 0 (9) 1 (13) table 7 - 14 i nput parameter of vibration m odule
n umaker brick dec 23 , 201 6 page 67 of 71 rev 1 . 00 nu maker brick design g uide sonar m odule 7.5 d ata n ame d ata c ontent d ata l ength i 2 c a ddress 24 2 bytes device d escript or d ata l ength 26 2 bytes report d escript or d ata l ength 36 2 bytes get i nput d ata l ength 5 2 bytes set o utput d ata l ength 0 2 bytes get f eature d ata l ength 6 2 bytes set f eature d ata l ength 6 2 bytes company c ode 0 2 bytes device c oe 0 2 bytes product c ode 0 2 bytes firmware v ersion 0 2 bytes device c lass c ode 0 2 bytes reserved 0 2 bytes reserved 0 2 bytes table 7 - 15 d evice d escriptor of s onar m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) sleep p eriod 5 2 bytes 0 ms (10) 1024 ms (14) distance a larm va lue 17 2 bytes 0 cm (10) 200 cm (14) table 7 - 16 feature parameter of s onar m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) distance v alue 5 2 bytes 0 (10) 400 cm (14) distance a larm f lag 17 1 byte 0 (9) 1 (13) table 7 - 17 i nput parameter of s onar m odule
n umaker brick dec 23 , 201 6 page 68 of 71 rev 1 . 00 nu maker brick design g uide t emperature m odule 7.6 d ata n ame d ata c ontent d ata l ength i 2 c a ddress 25 2 bytes device d escript or d ata l ength 26 2 bytes report d escript or d ata l ength 58 2 bytes get i nput d ata l ength 8 2 bytes set o utput d ata l ength 0 2 bytes get f eature d ata l ength 8 2 bytes set f eature d ata l ength 8 2 bytes company c ode 0 2 bytes device c ode 0 2 bytes product c ode 0 2 bytes firmware v ersion 0 2 bytes device c lass c ode 0 2 bytes reserved 0 2 bytes reserved 0 2 bytes table 7 - 18 d evice d escriptor of temperature m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) sleep p eriod 5 2 bytes 0 ms (10) 1024 ms (14) temperature a larm v alue 17 2 bytes 0 humidity a larm v alue 29 2 bytes 0 % (10) 100 % (14) table 7 - 19 feature parameter of temperature m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) temperature v alue 5 2 bytes 0 (10) 100 humidity v alue 17 2 bytes 0 (10) 100 % (14) temperature a larm f lag 29 1 byte 0 (9) 1 (13) humidity a larm f lag 41 1 byte 0 (9) 1 (13) table 7 - 20 i nput parameter of temperature m odule
n umaker brick dec 23 , 201 6 page 69 of 71 rev 1 . 00 nu maker brick design g uide d ata n ame d ata c ontent d ata l ength i 2 c a ddress 24 2 bytes device d escript or d ata l ength 26 2 bytes report d escript or d ata l ength 36 2 bytes get i nput d ata l ength 5 2 bytes set o utput d ata l ength 0 2 bytes get f eature d ata l ength 6 2 bytes set f eature d ata l ength 6 2 bytes company c ode 0 2 bytes device c ode 0 2 bytes product c ode 0 2 bytes firmware v ersion 0 2 bytes device c lass c ode 0 2 bytes reserved 0 2 bytes reserved 0 2 bytes table 7 - 21 d evice d escriptor of g as m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) sleep p eriod 5 2 bytes 0 ms (10) 1024 ms (14) g as a larm v alue 17 2 bytes 0 cm (10) 100 % (14) table 7 - 22 feature parameter of g as m odule parameter n ame parameter a ddress parameter l ength m inimum ( position ) m aximum ( position ) g as v alue 5 2 bytes 0 (10) 100 % (14) g as a larm f lag 17 1 byte 0 (9) 1 (13) table 7 - 23 i nput parameter of g as m odule
n umaker brick dec 23 , 201 6 page 70 of 71 rev 1 . 00 nu maker brick design g uide 8 revision history date rev ision description 201 6 . 1 2 . 23 1.00 1. initially issued.
n umaker brick dec 23 , 201 6 page 71 of 71 rev 1 . 00 nu maker brick design g uide important notice nuvoton products are neither intended nor warranted for usage in systems or equipment, any malfunction or failure of which may cause loss of human life, bodily injury or severe property damage. such applications are deemed, insecure usage. insecure usage inclu des, but is not limited to: equipment for surgical implementation, atomic energy control instruments, airplane or spaceship instruments, the control or operation of dynamic, brake or safety systems designed for vehicular use, traffic signal instruments, al l types of safety devices, and other applications intended to support or sustain life. all insecure usage shall be made at customers risk, and in the event that third parties lay claims to nuvoton as a result of customers insecure usage, customer shall indemnify the damages and liabilities thus incurred by nuvoton.


▲Up To Search▲   

 
Price & Availability of NUMAKER

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X